<?php

require_once('config/maptrick.conf.php');
require_once(SITE_ROOT . 'lib/SmartyMaptrick.class.php');
require_once(SITE_ROOT . 'class/logic/LogicHoC.class.php');
require_once(SITE_ROOT . 'class/Exceptions.class.php');
require_once(SITE_ROOT . 'class/bean/Team.class.php');
require_once(SITE_ROOT . 'config/session.php');

	$smarty = new SmartyMaptrick();
	
	if (isset($_SESSION['team'])) $teamID = $_SESSION['team'];
	if (isset($_GET['team'])) $teamID = $_GET['team'];
		
	if (preg_match("/^[0-9]{1,7}$/", $teamID) && $teamID > 0) {
		$_SESSION['team'] = $teamID;
		$smarty->assign('showHoC', true);
	
		try {
			$logicHoC = LogicHoC::getInstance();				
			$positions = $logicHoC->getHoCRanks($teamID);
			
			$smarty->assign("team", $positions->getTeam());
			$smarty->assign("country", $positions->getCountry());
			
			$smarty->assign('hoc_title', "Rank in Hall of Cool");
			$smarty->assign('rank_global_away_cool', $positions->getGlobalAwayCoolness());
			$smarty->assign('rank_global_away_flag', $positions->getGlobalAwayFlags());
			$smarty->assign('rank_global_home_cool', $positions->getGlobalHomeCoolness());
			$smarty->assign('rank_global_home_flag', $positions->getGlobalHomeFlags());
			$smarty->assign('rank_global_and_cool', $positions->getGlobalAndCoolness());
			$smarty->assign('rank_global_and_flag', $positions->getGlobalAndFlags());
			$smarty->assign('rank_global_or_cool', $positions->getGlobalOrCoolness());
			$smarty->assign('rank_global_or_flag', $positions->getGlobalOrFlags());
			$smarty->assign('rank_global_plus_cool', $positions->getGlobalPlusCoolness());
			$smarty->assign('rank_global_plus_flag', $positions->getGlobalPlusFlags());
			$smarty->assign('rank_country_away_cool', $positions->getCountryAwayCoolness());
			$smarty->assign('rank_country_away_flag', $positions->getCountryAwayFlags());
			$smarty->assign('rank_country_home_cool', $positions->getCountryHomeCoolness());
			$smarty->assign('rank_country_home_flag', $positions->getCountryHomeFlags());
			$smarty->assign('rank_country_and_cool', $positions->getCountryAndCoolness());
			$smarty->assign('rank_country_and_flag', $positions->getCountryAndFlags());
			$smarty->assign('rank_country_or_cool', $positions->getCountryOrCoolness());
			$smarty->assign('rank_country_or_flag', $positions->getCountryOrFlags());
			$smarty->assign('rank_country_plus_cool', $positions->getCountryPlusCoolness());
			$smarty->assign('rank_country_plus_flag', $positions->getCountryPlusFlags());
			
			$smarty->assign('hocranks', $positions->getConferenceCode());			
		}
		catch (LeagueNotAvailableException $lnae) {
			$smarty->assign('showHoC', false);
		}
	}
	else $smarty->assign('showHoC', false);
	
	$smarty->display('coolness_hoc.tpl');
	
?>